package com.qf.test;

import com.qf.service.AccountService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import javax.xml.bind.annotation.XmlAccessOrder;

/**
 * @Description: 公用常量
 * @Data: 2022/8/28 11:50
 * @Pacakge: com.qf.test
 * @ClassName: AccountTest02
 * @Author: fan
 */
public class AccountTest02 {
    public static void main(String[] args) {
        //通过顶层容器BeanFactory获取bean实例
        //顶层容器的特点:
        //容器初始化的时候,bean不会立即初始化,而是获取的时候才会进行初始化操作
        //1>获取配置文件
        Resource classPathResource = new ClassPathResource("springconfig.xml");
        //2>通过BeanFactory加载配置文件
        BeanFactory beanFactory = new XmlBeanFactory(classPathResource);
        //3>获取对应的bean实例
        AccountService accountService =(AccountService) beanFactory.getBean("accountService");
        //4>获取对应方法
        accountService.addAccount();
    }

}
